package com.sky.mapper;

import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface DishMapper {

    /**
     * 根据分类id查询菜品数量
     *
     * @param categoryId
     * @return
     */
    @Select("select count(id) from dish where category_id = #{categoryId}")
    Integer countByCategoryId(Long categoryId);

    /**
     * 插入菜品数据
     *
     * @param dish
     */
    @Insert("insert into dish (name, category_id, price, image, description, create_time, update_time, create_user, update_user,status)values (#{name}, #{categoryId}, #{price}, #{image}, #{description}, #{createTime}, #{updateTime}, #{createUser}, #{updateUser},#{status})")
    @Options(useGeneratedKeys = true, keyColumn = "id", keyProperty = "id")
    void insertDish(Dish dish);

    /**
     * 菜品查询
     *
     * @param dishPageQueryDTO
     * @return
     */

    List<DishVO> pageQuery(DishPageQueryDTO dishPageQueryDTO);


    /**
     * 根据id查询菜品
     *
     * @param id
     * @return
     */
    @Select("select * from dish where id = #{id}")
    Dish getById(Long id);

    /**
     * 批量删除菜品
     *
     * @param ids
     */
    void deleteDish(List<Long> ids);


    /**
     * 修改菜品数据
     *
     * @param dish
     */
    void update(Dish dish);

    /**
     * 根据id查询菜品和口味
     *
     * @param id
     * @return
     */
    DishVO getDishById(Long id);

    /**
     * 根据分类id查询菜品
     *
     * @param categoryId
     * @return
     */
    @Select("select * from dish where category_id = #{categoryId}")
    List<Dish> getByCategoryId(Long categoryId);

    /**
     * 修改菜品状态
     */
    void updateStatus(Dish dish);

    /**
     * 根据ID列表查询菜品
     *
     * @param ids 菜品ID列表
     * @return 菜品列表
     */
    List<Dish> getByIds(List<Long> ids);
}
